<template>
  <div>
    <el-dialog title="新增" :visible.sync="dialogVisible" width="500px" :before-close="closeEditDialog"
      :close-on-click-modal="false" :append-to-body="true">
      <el-form :model="addInfo" :rules="rules" ref="refAddInfo" label-width="100px">

        <el-form-item size="small" label="配置名" prop="configKey">
          <el-input clearable v-model.trim="addInfo.configKey" placeholder="请输入配置名"></el-input>
        </el-form-item>

        <el-form-item size="small" label="配置值">
          <el-input clearable v-model="addInfo.configValue" placeholder="请输入配置值"></el-input>
        </el-form-item>
        <el-form-item size="small" label="备注">
          <el-input type="textarea" :rows="3" placeholder="备注" v-model="addInfo.remark" maxlength="30" resize='none' :autosize="{ minRows: 2, maxRows: 5 }">
          </el-input>
        </el-form-item>

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeEditDialog" class="cancel-button">取 消</el-button>
        <el-button size="small" @click="addSubmit" v-preventReClick="1000" class="confirm-button">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { reqSystemConfigAdd } from "@/api/api";

export default {
  name: "add",
  components: {},
  data() {
    return {
      dialogVisible: false,
      addInfo: {
        configKey: "",
        configValue: "",
        remark: "",
      },
      // 表单验证规则
      rules: {
        configKey: [
          {
            required: true,
            message: "请输入配置名",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {},
  methods: {
    addSubmit() {
      this.$refs.refAddInfo.validate(async (valid) => {
        if (valid) {
          const res = await reqSystemConfigAdd(this.addInfo);
          if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
          this.$modal.notifySuccess("新增配置信息成功");
          this.closeEditDialog();
          this.$parent.SystemConfigList();
        }
      });
    },
    // 点击关闭弹框
    closeEditDialog() {
      this.$refs.refAddInfo.resetFields();
      this.addInfo = {
        configKey: "",
        configValue: "",
        remark: "",
      };
      this.dialogVisible = false;
    },
  },
};
</script>

<style lang="less" scoped>
@import url("../../common.less");
</style>